package com.hsy.linemoney.modules.my.editinformation;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.deparse.dpframe.ui.common.DPBusEvent;
import com.hsy.linemoney.R;
import com.hsy.linemoney.common.Consts;
import com.hsy.linemoney.modules.common.CommonBaseActivityWithSimpleActionBar;
import com.hsy.linemoney.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/1.
 */
public class SelectCityActivity extends CommonBaseActivityWithSimpleActionBar {
    private ListView listView;
    private List<String> listData;
    private LayoutInflater inflater;
    private Adapter adapter;
    private String province;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_city);
        setTitle("选择城市");
        inflater = LayoutInflater.from(this);
        province = getActivityStartExtra()[0];
        showList();
    }

    private void showList() {
        listView = F(R.id.listView);
        listData = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            listData.add("高薪园区" + i);

        }
        adapter = new Adapter();
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                CommonUtils.saveProvince(SelectCityActivity.this, province);
                CommonUtils.saveCity(SelectCityActivity.this, listData.get(position));
                DPBusEvent event = new DPBusEvent();
                event.what = Consts.BusEventCommands.FINISH_MY_SELECT_PROVINCE;
                postBusEvent(event);
                finish();
            }
        });
    }

    private class Adapter extends BaseAdapter {

        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public Object getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = inflater.inflate(R.layout.item_select_province_list, null);
            TextView name = (TextView) convertView.findViewById(R.id.province_name);
            name.setText(listData.get(position));
            return convertView;
        }
    }
}
